var arrayMap = new Array();
var mapEnCours = null;
var tab_infos = null;
var compoEnCours = null;
var ipEnCour = null;
var detailsTopologie = new Array('maininfos_details_details',
    'maininfos_details_interfaces',
    'maininfos_details_actions');
$( function() {
    mapEnCours = null;
    timers.add( "/topologie/lancementresp", new Array( visualisationTopologieResult, 0, 1 ) );
});
function OuvrirPanneauDetailTopologie() {
    $('#dock_bas_masque').removeClass('visible');
    $('#dock_bas_masque').addClass('invisible');
    $('#dock_bas').removeClass('invisible');
    $('#dock_bas').addClass('visible');
}
function FermerPanneauDetailTopologie() {
    $('#dock_bas_masque').removeClass('invisible');
    $('#dock_bas_masque').addClass('visible');
    $('#dock_bas').removeClass('visible');
    $('#dock_bas').addClass('invisible');
}
function OuvrirDetailTopologie(divName) {
    for (div in detailsTopologie)
    {
        $('#' + detailsTopologie[div]).removeClass('visible');
        $('#' + detailsTopologie[div]).addClass('invisible');
        $('#' + detailsTopologie[div] + '_link').removeClass('link_selectionner');
    }
    $('#' + divName).removeClass('invisible');
    $('#' + divName).addClass('visible');
    $('#' + divName + '_link').addClass('link_selectionner');
}
function ChargementDetailTopologie() {
  $.post(baseUrl + "/topologie/chargementdetailscomposantmap", function(a) {
    $("#maininfos_details_details").html(a)
  });
  $.post(baseUrl + "/topologie/chargementinterfacescomposantmap", function(a) {
    $("#maininfos_details_interfaces").html(a)
  });
  $.post(baseUrl + "/topologie/chargementactionscomposantmap", function(a) {
    $("#maininfos_details_actions").html(a)
  });
  $.post(baseUrl + "/topologie/chargementtitrecomposantmap", function(a) {
    $("#dock_bas_masque_gauche").html(a)
  })
}
function visualisationTopologie(a) {
  if(tabOuverte["topologie/"] != undefined) {
    $("#tabs").tabs("select", "#" + tabOuverte["topologie/"].id);
    var b = $tabs.tabs("option", "selected");
    b != 0 && $("#tabs").tabs("remove", b)
  }
  arrayMap[a] = [];
  mapEnCours = a;
  ajouterItem("Topologie : " + a, "topologie/");
  $.ajax({type:"POST", url:baseUrl + "/topologie/lancement/", success:attenteReponse, dataType:"json", async:false, data:{name:a}})
}
function visualisationTopologieResult(a) {
  if(a != null) {
    arrayMap[a.nameMap].img = baseUrl + a.img;
    arrayMap[a.nameMap].nbNode = a.nbNode;
    mapEnCours = a.nameMap;
  }
}
function LoadSvg() {
    $('.node').dblclick(DemandeInfosNode);
    $('svg').width($("#mainimg_img").width());
    $('svg').height($("#mainimg_img").height());
}
function DemandeInfosNode(a) {
  $("#tabs_infos_map").removeClass("invisible");
  $("#tabs_infos_map").addClass("visible");
  $.post(baseUrl + "/topologie/changementcomposantmap", {name:a.currentTarget.firstChild.textContent});
  ChargementDetailTopologie();
  OuvrirDetailTopologie("maininfos_details_details")
}
function deleteMap() {
  $.post(baseUrl + "/creation/deletemap/", {name:mapEnCours}, null, "json");
  var indexNumber = $tabs.tabs('option', 'selected');
  if (indexNumber != 0)
    $("#tabs").tabs("remove", indexNumber);
  maptree = $("#divMapTree");
  maptree.find("*").remove();
  getListMap();
  alertGrowl("Topologie", mapEnCours + " supprimer")
}
valid.add("deleteMap", deleteMap);
function actionMonitor() {
  $.post(baseUrl + "/topologie/actionmoniteur", {name:compoEnCour}, alertGrowl(TOPOLOGI_MONITOR_TXT, TOPOLOGI_MONITOR_ADD), "json")
}
function actionCommand() {
  getListUser();
  var btns = {};
  btns[BUTTON_CANCEL] = function() {$(this).dialog("close")};
  btns[BUTTON_EXEC] = function() {$(this).dialog("close"); ajouterItem("Console", "console/"); sendCommand(false, ipEnCour)}
  diagCommand.dialog({autoOpen:false, draggable:true, width:"auto", modal:true, buttons:btns});
  diagCommand.dialog("open")
}
function actionRestore() {
  getListUser();
  getListConf(false, ipEnCour);
  var btns = {};
  btns[BUTTON_CANCEL] = function() {$(this).dialog("close")};
  btns[BUTTON_RESTORE] = function() {$(this).dialog("close"); makeRestore(false, ipEnCour) };
  diagRestore.dialog({autoOpen:false, draggable:true, width:"auto", modal:true, buttons:btns});
  diagRestore.dialog("open")
}
function actionBackup() {
  getListUser();
  var btns = {};
  btns[BUTTON_CANCEL] = function() {$(this).dialog("close")};
  btns[BUTTON_SAVE] = function() {$(this).dialog("close"); makeBackup(false, ipEnCour)};
  diagBackup.dialog({autoOpen:false, draggable:true, width:"auto", modal:true, buttons:btns});
  diagBackup.dialog("open")
}
function actionLog() {
  getListFilter();
  var btns = {};
  btns[BUTTON_CANCEL] = function() {$(this).dialog("close")};
  btns[BUTTON_EXEC] = function() {$(this).dialog("close"); ajouterItem("Log", "log/"); getlog(false, ipEnCour)};
  diagLog.dialog({autoOpen:false, draggable:true, width:"auto", modal:true, buttons:btns});
  diagLog.dialog("open")
}